package org.dding.core.system.service;

import org.dding.msc.exception.ServiceNotFoundException;
import org.dding.msc.exception.StartException;
import org.dding.msc.exception.StopException;
import org.dding.msc.exception.WaitingException;
import org.dding.msc.service.Service;
import org.dding.msc.service.StartContext;
import org.dding.msc.service.StopContext;
import org.hsqldb.server.Server;

public class HsqldbService implements Service<Object> {

	private Server hsql;

	@Override
	public Object getValue() throws IllegalStateException, IllegalArgumentException {
		return null;
	}

	@Override
	public void start(StartContext context) throws ServiceNotFoundException, StartException {
		hsql = new Server();
		hsql.setSilent(true);
		hsql.setPort(9090);
		hsql.setLogWriter(null);
		hsql.setDatabasePath(0, "file:data/cms");
		hsql.setDatabaseName(0, "cms");
		hsql.start();
	}

	@Override
	public void stop(StopContext context) throws StopException {
		if (hsql != null)
			hsql.stop();
	}

	@Override
	public void waiting(boolean enable) throws WaitingException {
		// TODO Auto-generated method stub

	}

}
